
#ifndef RTMP_INCLUDE_CONNECTION_H_
#define RTMP_INCLUDE_CONNECTION_H_

#include <cstdint>
#include <memory>
#include <vector>
#include "../../public_module/public_module_define.h"
#ifndef RTMP_INCLUDE_MESSAGE_H_
#include "rtmp_message.h"
#endif
#ifndef RTMP_INCLUDE_PARSER_H_
#include "rtmp_parser.h"
#endif
#ifndef RTMP_INCLUDE_PROCESS_H_
#include "rtmp_process.h"
#endif

class RtmpMediaResource;

class RtmpConnection : public std::enable_shared_from_this<RtmpConnection>
{
public:
    RtmpConnection(std::shared_ptr<Connection> conn);
    RtmpConnection(std::shared_ptr<Client>     client, bool test);
    ~RtmpConnection();
    void Resource(std::shared_ptr<RtmpMediaResource> resource);
    std::shared_ptr<RtmpMediaResource> Resource();
    void SendRespMsg(std::shared_ptr<RtmpMessage> msg);
    void SendRespMsg(std::vector<std::shared_ptr<RtmpMessage>> msg_vec);
    RtmpConnectState State();
    void UpdateState(RtmpConnectState state);
    int  ProcessHandShake(const uint8_t * data, int length);
    void ProcessMsg();
    int  PushRtmpData(const uint8_t * data, int length);
    void ReleaseStream();
    int64_t Index();
    void Remove();
    void SendData(const uint8_t * data, int length);
private:
    std::shared_ptr<Connection> m_conn;
    std::shared_ptr<Client>     m_client;
    std::shared_ptr<RtmpMediaResource>   m_resource;
    int m_is_push_role;
private:
    RtmpConnectState  m_state;
    RtmpMessageBuffer m_rtmp_msg;
    RtmpMsgProceess   m_rtmp_proc;
};

#endif
